<template>
  <!-- 业务参数维护添加-->
  <el-dialog
    :title="title"
    center
    :visible.sync="openState"
    width="1024px"
    :close-on-click-modal="false"
    :before-close="handleClose"
  >
    <el-form ref="addForm" :model="addForm" :rules="addRules" label-width="110px">
      <!--业务参数维护添加-->

      <el-row>
        <el-col :span="12">
          <el-form-item label="系统号" prop="sysFlg">
            <el-input v-model="addForm.sysFlg" placeholder="系统号" maxlength="4"/>
          </el-form-item>
        </el-col>
      </el-row>

      <el-row :gutter="20">
        <el-col :span="12">
          <el-form-item label="内部机构号" prop="orgNo">
            <el-input v-model="addForm.orgNo" placeholder="内部机构号" :disabled="true" style="width: 103%" />
          </el-form-item>
        </el-col>

<!--        <el-col :span="12">
          <el-button type="primary" icon="el-icon-search" plain @click="brnoQry('brno')">内部机构查询</el-button>
        </el-col>-->
        <el-col :span="12">
          <el-form-item label="内部机构名称" prop="orgname">
            <el-input v-model="addForm.orgname" placeholder="内部机构名称" :disabled="true" />
          </el-form-item>
        </el-col>
      </el-row>


      <el-row>
        <el-col :span="12">
          <el-form-item label="参数代码" prop="paraCode">
            <el-input v-model="addForm.paraCode" placeholder="参数代码" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="参数名称" prop="paraName">
            <el-input v-model="addForm.paraName" placeholder="参数名称" />
          </el-form-item>
        </el-col>
      </el-row>

      <el-row>
        <el-col :span="12">
          <el-form-item label="参数值" prop="paraValue">
            <el-input v-model="addForm.paraValue" placeholder="参数值" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="参数描述" prop="paraDesc">
            <el-input v-model="addForm.paraDesc" placeholder="参数描述" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <brno-search-dialog ref="brnoSearchDialog" @confirm="confirmBrno"></brno-search-dialog>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">提 交</el-button>
    </div>
  </el-dialog>
</template>
<script>
import { bizParaAdd } from "@/api/cnaps/bizMng/paraMng.js";
import BrnoSearchDialog from "@/views/components/BrnoSearchDialog";
import { listPageMixin } from "@/libs/listPageMixin";
import { mapGetters } from "vuex";

export default {
  name: "bizParaAddDialog",
  mixins: [listPageMixin],
  components: {
    BrnoSearchDialog,
  },
  computed: {
    ...mapGetters(["globalBusData"]),
  },

  data() {
    return {
      title: "",
      // 是否显示弹出层
      openState: false,
      // 字段可编辑控制

      //数据字典
      searchFormDictList: [],
      // 表单参数
      addForm: {},
      // 表单校验
      addRules: {
        sysFlg: [{ required: true, message: "请输入系统号", trigger: "blur" }],
        orgNo: [{ required: true, message: "请输入内部机构号", trigger: "blur" }],
        paraCode: [{ required: true, message: "请输入参数代码", trigger: "blur" }],
        paraName: [{ required: true, message: "请输入参数名称", trigger: "blur" }],
        paraValue: [{ required: true, message: "请输入参数值", trigger: "blur" }],
        paraDesc: [{ required: true, message: "请输入参数描述", trigger: "blur" }],
      },
      opButtonList: () => {
        return [];
      },
    };
  },
  mounted() {},
  methods: {
    // 表单重置
    reset() {
      this.resetForm("addForm");
      this.$set(this, "addForm", {});
    },
    // 关闭回掉
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          this.reset();
          done();
        })
        .catch((_) => {});
    },
    show() {
      this.title = "业务参数维护新增";
      this.$set(this.addForm, "orgNo", this.globalBusData.brno);
      this.$set(this.addForm, "orgname", this.globalBusData.brname);
      this.openState = true;
    },

    /** TODO提交按钮 */
    submitForm: function () {
      this.$refs["addForm"].validate((valid) => {
        if (valid) {
          this.submit();
        }
      });
    },

    submit() {
      bizParaAdd(this.addForm).then((res) => {
        if (res.code === "S") {
          this.msgSuccess("提交成功");
          this.cancel();
        }
      });
    },

    cancel() {
      this.openState = false;
      this.reset();
      this.$emit("editComplete", true);
    },

    brnoQry() {
      this.$refs.brnoSearchDialog.show();
    },

    confirmBrno(fromFlag, row) {
      this.$set(this.addForm, "orgNo", row.brno);
      this.$set(this.addForm, "orgname", row.brname);
    },
  },
};
</script>
<style>
.label-header-msg {
  font-weight: bold;
}

.form-card {
  margin-bottom: 10px;
}
</style>
